﻿<%@ Page Title="Advance Payment" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true"
    CodeBehind="AdvancePayment.aspx.cs" Inherits="VSM.AdvancePayment" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script type="text/javascript">
        function OpenBP() {
            var url = "../../BPPopup.aspx?CardType=C";
            Main.openCustomDialog(url, 600, 610, "Business Partner List");
        }

        function OpenAccount(accountCode) {
            var url = "../../AccountPopup.aspx?AccountCode=" + accountCode;
            Main.openCustomDialog(url, 600, 610, "Chart of Account");
        }

        function OpenDocList(docktype, payNoDoc) {
            var url = "../../DocumentList.aspx?DocType=" + docktype + "&PayNoDoc=" + payNoDoc
            Main.openCustomDialog(url, 800, 610, "Advance Payment List");
        }
    </script>
    <div>
        <asp:UpdatePanel ID="updatePanel" runat="server">
            <ContentTemplate>
                <asp:HiddenField ID="hdnIsUpdate" runat="server" />
                <asp:HiddenField ID="hdnStatus" runat="server" />
                <h2>
                    &nbsp;<asp:Label ID="lblTitle" runat="server" Text="Advance Payments"></asp:Label>
                </h2>
                <div style="margin-left: 5px; width: 99%;">
                    <hr />
                    <table border="0" width="100%" style="background-color: #D1D4D8; font-weight: bold;">
                        <tr>
                            <td style="border-bottom: dotted 1px #808080; vertical-align: bottom; width: 10%;">
                                <asp:Label ID="lblDocNo" runat="server" Text="Document No.:"></asp:Label>
                            </td>
                            <td style="width: 20%;">
                                <asp:TextBox ID="txtIncNo" runat="server" BackColor="#E6E6E6" ReadOnly="True" 
                                    Width="100px"></asp:TextBox>
                            </td>
                            <td style="border-bottom: dotted 1px #808080; vertical-align: bottom; width: 100px;" >
                                <asp:Label ID="lblDueDate" runat="server" Text="Due Date:"></asp:Label>
                            </td>
                            <td align="left">
                                <asp:TextBox ID="txtDueDate" runat="server" Width="100px"></asp:TextBox>
                                <cc1:CalendarExtender ID="txtDueDate_CalendarExtender" runat="server" 
                                    Format="dd/MM/yyyy" PopupButtonID="imgDueDate" TargetControlID="txtDueDate">
                                </cc1:CalendarExtender>
                                <asp:ImageButton ID="imgDueDate" runat="Server" AlternateText="Click to show calendar" ImageUrl="~/Images/Calendar_scheduleHS.png" />
                                <asp:Label ID="lblDueDateRequired" runat="server" ForeColor="Red" Text="*"></asp:Label>
                            </td>
                            <td align="right">
                                <asp:Button ID="btnNew" runat="server" BorderStyle="Solid" 
                                    Style="background-image: url('/Images/bgButton.png'); background-repeat: no-repeat;" 
                                    Text="New" Width="50px" onclick="btnNew_Click" />
                                <asp:Button ID="btnDocList" runat="server" BorderStyle="Solid" 
                                    OnClientClick="OpenDocList('24','Y'); return false;" 
                                    Style="background-image: url('/Images/bgButton.png'); background-repeat: no-repeat;" 
                                    Text="List" Width="50px" />
                            </td>
                        </tr>
                        <tr>
                            <td style="border-bottom: dotted 1px #808080; vertical-align: bottom; height: 7px">
                                <asp:Label ID="lblPostingDate" runat="server" Text="Posting Date:"></asp:Label>
                            </td>
                            <td style="height: 7px">
                                <asp:TextBox ID="txtPostingDate" runat="server" Width="100px"></asp:TextBox>
                                <cc1:CalendarExtender ID="txtPostingDate_CalendarExtender" runat="server" 
                                    Format="dd/MM/yyyy" PopupButtonID="imgPostingDate" TargetControlID="txtPostingDate">
                                </cc1:CalendarExtender>
                                <asp:ImageButton ID="imgPostingDate" runat="Server" AlternateText="Click to show calendar" ImageUrl="~/Images/Calendar_scheduleHS.png" />
                                <asp:Label ID="lblPosDateRequired" runat="server" ForeColor="Red" Text="*"></asp:Label>
                            </td>
                            <td style="border-bottom: dotted 1px #808080; vertical-align: bottom; height: 7px" >
                                <asp:Label ID="lblDocDate" runat="server" Text="Doc. Date:"></asp:Label>
                            </td>
                            <td colspan="2" >
                                    <asp:TextBox ID="txtDocDate" runat="server" Width="100px"></asp:TextBox>
                                    <cc1:CalendarExtender ID="txtDocDate_CalendarExtender" runat="server" 
                                        Format="dd/MM/yyyy" PopupButtonID="imgDocDate" TargetControlID="txtDocDate">
                                    </cc1:CalendarExtender>
                                    <asp:ImageButton ID="imgDocDate" runat="Server" AlternateText="Click to show calendar" ImageUrl="~/Images/Calendar_scheduleHS.png" />
                                    <asp:Label ID="lblDocDateRequired" runat="server" ForeColor="Red" Text="*"></asp:Label>
                            </td>
                        </tr>

                    </table>
                    <table id="Table1" width="100%" style="font-weight: bold">
                        <tr>
                            <td class="FormLineItemAlt" style="white-space: nowrap; width: 10%" valign="middle">Customer:</td>
                            <td class="FormLineItemAlt" style="width: 40%; ">
                                <asp:TextBox ID="txtCustomerCode" runat="server" ReadOnly="True" Width="100px" BackColor="#E6E6E6"></asp:TextBox>
                                <asp:TextBox ID="txtCustomerName" runat="server" Width="250px" 
                                    BackColor="#E6E6E6" ReadOnly="True"></asp:TextBox>
                                <asp:Label ID="lblCustRequired" runat="server" ForeColor="Red" Text="*"></asp:Label>
                                <asp:Button ID="btnSelectBP" runat="server" OnClientClick="OpenBP(); return false;"
                                    Text="..." 
                                    Style="background-image: url('/Images/bgButton.png'); background-repeat: no-repeat; font-weight: bold" />
                            </td>
                            <td class="FormLineItemAlt" style="width: 10%; ">
                                Payment Means:</td>
                            <td class="FormLineItemAlt">
                                <asp:DropDownList ID="ddlPaymentMeans" runat="server" AutoPostBack="True" 
                                    onselectedindexchanged="ddlPaymentMeans_SelectedIndexChanged">
                                    <asp:ListItem Value="B">Bank Transfer</asp:ListItem>
                                    <asp:ListItem Value="C">Cash</asp:ListItem>
                                </asp:DropDownList>
                            </td>
                        </tr>
                        <tr>
                            <td class="FormLineItem" valign="middle" style="width: 10%">
                                <asp:Label ID="lblConPersonName" runat="server">Contact Person:</asp:Label> 
                            </td>
                            <td class="FormLineItem">
                                <asp:TextBox ID="txtCntctName" Width="86%" runat="server"></asp:TextBox>                            
                            </td>
                            <td class="FormLineItem" style="width: 10%;">
                                <asp:Label ID="lblSONo" runat="server" Text="Sale Order No.:" ></asp:Label>
                                <asp:Label ID="lblGLAccount" runat="server" Text="G/L Account:" Visible="False"></asp:Label>
                            </td>
                            <td class="FormLineItem" >
                                <asp:TextBox ID="txtSONo" Text="" runat="server" Width="100px" 
                                    ontextchanged="txtSONo_TextChanged"></asp:TextBox>
                                <asp:Label ID="lblSONoRequired" runat="server" ForeColor="Red" Text="*"></asp:Label>
                                <asp:Button ID="btnFindSO" runat="server" Enabled="False" onclick="btnFindSO_Click" 
                                    Style="background-image: url('/Images/bgButton.png'); background-repeat: no-repeat; font-weight: bold" Text="Find SO Details" Width="100px" />

                                <asp:TextBox ID="txtAccountCode" runat="server" BackColor="#E6E6E6" 
                                    ReadOnly="True" Width="100px" Visible="False"></asp:TextBox>
                                <asp:TextBox ID="txtAccountName" runat="server" Width="70%" 
                                    BackColor="#E6E6E6" ReadOnly="True" Visible="False"></asp:TextBox>
                                <asp:Button ID="btnGLAccount" runat="server" 
                                    OnClientClick="OpenAccount(112); return false;" 
                                    Style="background-image: url('/Images/bgButton.png'); background-repeat: no-repeat; font-weight: bold" 
                                    Text="..." Enabled="False" Visible="False" />
                            </td>
                        </tr>
                        <tr>
                            <td class="FormLineItemAlt" valign="top" style="width: 10%">
                                <asp:Label ID="lblBillTo" runat="server">Bill To:</asp:Label> 
                            </td>
                            <td class="FormLineItemAlt">
                                <asp:TextBox ID="txtBillTo" TextMode="MultiLine" runat="server" Width="86%"></asp:TextBox>                            
                            </td>
                            <td class="FormLineItemAlt" valign="top" style="width: 10%">
                                <asp:Label ID="lblContractNo" runat="server">Contract No.:</asp:Label>
                            </td>
                            <td class="FormLineItemAlt" valign="top">
                                <asp:TextBox ID="txtContractNo" Text="" runat="server" Width="100px" 
                                    ontextchanged="txtContractNo_TextChanged"></asp:TextBox>
                                <asp:Label ID="lblContractNoRequired" runat="server" ForeColor="Red" Text="*"></asp:Label>
                                <asp:Button ID="btnContractNo" runat="server" onclick="btnContractNo_Click" 
                                    
                                    Style="background-image: url('/Images/bgButton.png'); background-repeat: no-repeat; font-weight: bold" 
                                    Text="Find SO Details" Width="100px" />
                            </td>
                        </tr>
                        <tr>
                            <td class="FormLineItem">Total Paid:</td>
                            <td class="FormLineItem" colspan="3">
                                <asp:TextBox ID="txtCustRemain" Style="text-align: right" runat="server" AutoPostBack="true"
                                    Width="150px" ontextchanged="txtCustRemain_TextChanged" ></asp:TextBox>
                            </td>
                        </tr>
                    </table>
                    <hr />
                    <div style="width: 100%">
                        <asp:GridView ID="grvSO" CssClass="GridInner" runat="server" Width="100%" BorderColor="White"
                            BackColor="White" AllowSorting="True" AutoGenerateColumns="False" CellPadding="2"
                            HeaderStyle-Height="27px" CellSpacing="2" HeaderStyle-VerticalAlign="Middle"
                            AllowPaging="True" OnPageIndexChanging="grvSearchResult_PageIndexChanging" 
                            PageSize="20" onrowcreated="grvSO_RowCreated" 
                            onrowdatabound="grvSearchResult_RowDataBound">
                            <PagerSettings Mode="NumericFirstLast" />
                            <PagerStyle BackColor="#70A0D0" Font-Bold="True" HorizontalAlign="Center" VerticalAlign="Middle" />
                            <RowStyle BackColor="#D9E0ED" BorderColor="White" BorderWidth="2px" Height="25px" />
                            <AlternatingRowStyle BackColor="#EEF1F7" BorderColor="White" BorderWidth="2px" />
                            <Columns>
                                <asp:CommandField HeaderText="Action" ShowDeleteButton="True" ShowEditButton="False"
                                    Visible="false" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="70px" />
<%--                                <asp:TemplateField HeaderText="Action">
                                    <ItemStyle HorizontalAlign="Center" Width="20px" />
                                    <HeaderStyle VerticalAlign="Middle" />
                                    <ItemTemplate>
                                        <asp:LinkButton ID="lnkDelete" runat="server" Text="Delete" TabIndex="-1" OnClick="lnkDelete_Click"></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>--%>
                                <asp:TemplateField HeaderText="#">
                                    <ItemStyle HorizontalAlign="Center" Width="20px" />
                                    <HeaderStyle VerticalAlign="Middle" />
                                    <ItemTemplate>
                                        <asp:Label ID="lblNo" runat="server" Text='<%# Bind("No") %>' BorderStyle="none" />
                                        <asp:HiddenField ID="hdnBaseLine" Value='<%# Bind("U_BaseLine") %>' runat="server" />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Selection">
                                    <ItemStyle HorizontalAlign="Center" Width="60px" />
                                    <HeaderStyle VerticalAlign="Middle" />
                                    <ItemTemplate>
                                        <asp:CheckBox ID="chkSelected" Checked='<%#Convert.ToBoolean(Eval("Selected")) %>'  OnCheckedChanged="chkSelected_CheckedChanged"  AutoPostBack="true"  runat="server" />
                                    </ItemTemplate>
                                </asp:TemplateField>

                                <asp:TemplateField HeaderText="Model" >
                                    <ItemStyle HorizontalAlign="Center" />
                                    <HeaderStyle VerticalAlign="Middle" />
                                    <ItemTemplate>
                                        <asp:Label ID="txtModel" runat="server" Text='<%# Bind("U_Model") %>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Product" >
                                    <ItemStyle HorizontalAlign="Center" />
                                    <HeaderStyle VerticalAlign="Middle" />
                                    <ItemTemplate>
                                        <asp:Label ID="txtProduct" runat="server" Text='<%# Bind("U_Product") %>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Color" >
                                    <ItemStyle HorizontalAlign="Center" />
                                    <HeaderStyle VerticalAlign="Middle" />
                                    <ItemTemplate>
                                        <asp:Label ID="txtColor" runat="server" Text='<%# Bind("U_Color") %>' />
                                    </ItemTemplate>
                                </asp:TemplateField>

                                <asp:TemplateField HeaderText="Item Code" Visible="false">
                                    <ItemStyle HorizontalAlign="Center" />
                                    <HeaderStyle VerticalAlign="Middle" />
                                    <ItemTemplate>
                                        <asp:Label ID="lblItemCode" runat="server" Text='<%# Bind("ItemCode") %>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Item Name">
                                    <ItemStyle HorizontalAlign="left" />
                                    <HeaderStyle VerticalAlign="Middle" Font-Bold="true" />
                                    <ItemTemplate>
                                        <asp:Label ID="txtItemName" runat="server" Text='<%# Bind("Dscription") %>' BorderStyle="none" />
                                    </ItemTemplate>
                                </asp:TemplateField>

                                <asp:TemplateField HeaderText="Qty.">
                                    <ItemStyle HorizontalAlign="Right" />
                                    <HeaderStyle VerticalAlign="Middle" Width="70px" />
                                    <ItemTemplate>
                                        <asp:Label ID="lblOrderQuantity" runat="server" Width="97%" Text='<%# Bind("Quantity")%>' Style="text-align: right" />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                 <asp:TemplateField HeaderText="Unit Price">
                                    <ItemStyle HorizontalAlign="Right" />
                                    <HeaderStyle VerticalAlign="Middle" Width="40px" />
                                    <ItemTemplate>
                                        <asp:Label ID="lblUnitPrice" runat="server" Style="text-align: right; width: 98%;" Text='<%# Bind("PriceBefDi")%>' />
                                    </ItemTemplate>
                                </asp:TemplateField>

                                <asp:TemplateField HeaderText="Line Total">
                                    <ItemStyle HorizontalAlign="Right" />
                                    <HeaderStyle VerticalAlign="Middle" />
                                    <ItemTemplate>
                                        <asp:Label ID="txtLineTotal" runat="server" Style="text-align: right; width: 98%;" Text='<%# Bind("LineTotal")%>' />
                                    </ItemTemplate>
                                </asp:TemplateField>

                                <asp:TemplateField HeaderText="Discount">
                                    <ItemStyle HorizontalAlign="Right" />
                                    <HeaderStyle VerticalAlign="Middle" Width="60px" />
                                    <ItemTemplate>
                                        <asp:Label ID="lblDiscount" runat="server" Style="text-align: right; width: 98%;" Text='<%# Bind("U_Discount")%>' />
                                    </ItemTemplate>
                                </asp:TemplateField>

                                <asp:TemplateField HeaderText="Incentive Disc.">
                                    <ItemStyle HorizontalAlign="Right" />
                                    <HeaderStyle VerticalAlign="Middle" Width="60px" />
                                    <ItemTemplate>
                                        <asp:Label ID="lblIncDisc" runat="server" Style="text-align: right; width: 98%;" Text='<%# Bind("U_IncentiveDiscount")%>' />
                                        <asp:HiddenField ID="hdnVatGroup" Value='<%# Bind("VatGroup") %>' runat="server" />
                                        <asp:HiddenField ID="hdnVatPrcnt" Value='<%# Bind("VatPrcnt") %>' runat="server" />
                                        <asp:HiddenField ID="hdnVatSum" Value='<%# Bind("VatSum") %>' runat="server" />
                                    </ItemTemplate>
                                </asp:TemplateField>

                                <asp:TemplateField HeaderText="Total Payments">
                                    <ItemStyle HorizontalAlign="Right" />
                                    <HeaderStyle VerticalAlign="Middle" Width="150px" />
                                    <ItemTemplate>
                                        <asp:Label ID="lbTotalPaymets" runat="server" Style="text-align: right" Width="97%" Text='<%# Bind("SumApplied")%>' />
                                    </ItemTemplate>
                                </asp:TemplateField>

                                <asp:TemplateField HeaderText="Remain">
                                    <ItemStyle HorizontalAlign="Right" />
                                    <HeaderStyle VerticalAlign="Middle" Width="150px" />
                                    <ItemTemplate>
                                        <asp:Label ID="lblRemain" runat="server" Width="97%" Text='<%# Bind("Remain")%>' Style="text-align: right" />
                                        <asp:HiddenField ID="hdnRemainOrg" Value='<%# Bind("Remain_Org") %>' runat="server" />
                                        <asp:HiddenField ID="hdnCardCode" Value='<%# Bind("CardCode") %>' runat="server" />
                                    </ItemTemplate>
                                </asp:TemplateField>

                                <asp:TemplateField HeaderText="Paid">
                                    <ItemStyle HorizontalAlign="Right" />
                                    <HeaderStyle VerticalAlign="Middle" Width="150px" />
                                    <ItemTemplate>
                                        <asp:TextBox ID="txtPaid" ReadOnly="true" runat="server" Width="97%" Text='<%# Bind("Paid") %>' BorderStyle="None" BackColor="Transparent"
                                            AutoPostBack="true" OnTextChanged="txtPaid_OnTextChanged" Style="text-align: right" />
                                    </ItemTemplate>
                                </asp:TemplateField>

                            </Columns>
                            <HeaderStyle BackColor="#6095C9" Font-Bold="true" ForeColor="#ffffff" Font-Overline="False"
                                Height="27px" VerticalAlign="Bottom" />
                            <EmptyDataTemplate>
                                <table class="GridInner" style="width: 100%; border-color: White;" border="1" rules="all" cellspacing="2" cellpadding="2">
                                    <tr valign="middle" style="height: 27px; color: white; font-weight: bold; text-decoration: none; background-color: rgb(96, 149, 201);">
                                        <th>
                                            <span>#</span>
                                        </th>
                                        <th>
                                            <span>Selection</span>
                                        </th>
                                        <th>
                                            <span>Model</span>
                                        </th>
                                        <th>
                                            <span>Product</span>
                                        </th>
                                        <th>
                                            <span>Color</span>
                                        </th>
                                        <th>
                                            <span>Item Name</span>
                                        </th>
                                         <th>
                                            <span>Unit Price</span>
                                        </th>
                                        <th>
                                            <span>Qty.</span>
                                        </th>
                                        <th>
                                            <span>Line Total</span>
                                        </th>
                                        <th>
                                            <span>Discount</span>
                                        </th>
                                        <th>
                                            <span>Incentive Disc.</span>
                                        </th>
                                        <th>
                                            <span>Total Payments</span>
                                        </th>
                                        <th>
                                            <span>Remain</span>
                                        </th>
                                        <th>
                                            <span>Paid</span>
                                        </th>
                                    </tr>
                                    <tr>
                                        <td colspan="14">
                                            <span>No Data</span>
                                        </td>
                                    </tr>
                                </table>
                            </EmptyDataTemplate>
                        </asp:GridView>
                    </div>
                    <hr width="100%" />
                </div>
                <table width="100%" border="0">
                    <tr>
                        <td valign="top" style="width: 50%;">
                            <table>
                                <tr>
                                    <td style="width: 150px">
                                        <strong>Remarks :</strong>
                                    </td>
                                    <td style="width: 100%;">
                                        <asp:TextBox runat="server" ID="txtRemarks" Height="71px" TextMode="MultiLine" Width="98%"></asp:TextBox>
                                    </td>
                                </tr>
                            </table>
                        </td>
                        <td style="width: 50%;">
                            <div style="margin-left: 50%; margin-right: 0px;">
                                <table border="0" >
                                    <tr valign="middle" style="height: 27px; color: black; font-weight: bold; text-decoration: none; background-color: #D9E0ED;">
                                        <td align="right">Payment Account:</td>
                                        <td style="width: 150px" align="right">
                                            <asp:TextBox ID="txtPaymentAccount" runat="server" BackColor="Transparent" Font-Bold="True" Style="text-align: right; "
                                                ForeColor="Red" Width="97%" BorderStyle="None" ReadOnly="True" >0.00</asp:TextBox>
                                        </td>
                                    </tr>
                                    <tr valign="middle" style="height: 27px; color: black; font-weight: bold; text-decoration: none;
                                        background-color: #D9E0ED;">
                                        <td align="right">Total Amount Due</td>
                                        <td style="width: 150px" align="right">
                                            <asp:Label ID="lblTotalAmountDue" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
                                        </td>
                                    </tr>
                                    <tr valign="middle" style="height: 27px; color: white; font-weight: bold; text-decoration: none; background-color: rgb(96, 149, 201);">
                                        <td align="right">Open Balance</td>
                                        <td style="width: 150px" align="right">
                                            <asp:Label ID="lblOpenBalance" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <div style="margin-left: 5px; width: 99%;">
                                <hr />
                            </div>
                            <table style="width: 100%">
                                <tr>
                                    <td style="width: 400px;">
                                        <asp:Button ID="btnSave" runat="server" Text="Save" Style="background-image: url('/Images/bgButton.png');
                                            background-repeat: no-repeat; color: White;" OnClick="btnSave_Click" OnClientClick="return confirm('Are you sure? After saved, you cannot edit anythings in this Advance Payment.');"
                                            BorderStyle="Solid" Width="60px" Enabled="False" />
                                        <asp:Button ID="btnCancel" runat="server" Text="Cancel" Style="background-image: url('/Images/bgButton.png');
                                            background-repeat: no-repeat; color: White;" BorderStyle="Solid" 
                                            OnClick="btnCancel_Click" Width="60px" Enabled="False" />
                                        <asp:Button ID="btnLastRecord" runat="server" BorderStyle="Solid" 
                                            OnClick="btnLastRecord_Click" 
                                            Style="background-image: url('/Images/bgButton.png'); background-repeat: no-repeat; color: White;" 
                                            Text="&gt;&gt;" ToolTip="Last record" Width="60px" />
                                    </td>
                                    <td>
                                        <asp:Label ID="lblError" runat="server" Visible="False" Font-Bold="True" ForeColor="Red"></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
</asp:Content>
